/**
 * C Programming: A Modern Approach
 *
 * version: 2nd
 * author: K.N.King
 * http://knking.com/books/c2
 */

#include <stdio.h>

/**
 *
 */

int main(void) {
    float loan = 0.0f;
    float interest_rate = 0.0f;
    float monthly_payment = 0.0f;
    float first_remaining = 0.0f;
    float second_remaining = 0.0f;
    float third_remaining = 0.0f;

    // Get loan
    printf("Enter amount of loan: ");
    scanf("%f", &loan);

    // Get interest rate
    printf("Enter interest rate: ");
    scanf("%f", &interest_rate);

    // Get monthly payment
    printf("Enter monthly payment: ");
    scanf("%f", &monthly_payment);

    first_remaining = loan * (1 + (interest_rate / 100) / 12) - monthly_payment;
    second_remaining =
        first_remaining * (1 + (interest_rate / 100) / 12) - monthly_payment;
    third_remaining =
        second_remaining * (1 + (interest_rate / 100) / 12) - monthly_payment;

    printf("\nBalance remaining after first payment: %.2f\n", first_remaining);
    printf("Balance remaining after second payment: %.2f\n", second_remaining);
    printf("Balance remaining after third payment: %.2f\n", third_remaining);

    return 0;
}

/*
output:
Enter amount of loan: 20000.00
Enter interest rate: 6.0
Enter monthly payment: 386.66

Balance remaining after first payment: 19713.34
Balance remaining after second payment: 19425.25
Balance remaining after third payment: 19135.71
*/